# -*- mode: python -*-

Import("env")

env.Library('serverauth', ['mongo_authentication_session.cpp'])

generateActionTypes = env.Command(
    target=['action_type.h', 'action_type.cpp'],
    source=['generate_action_types.py', 'action_types.txt'],
    action='$PYTHON $SOURCES $TARGETS')
env.Alias('generated-sources', generateActionTypes)

# Just the data structures used
env.Library('authcore', ['action_set.cpp',
                         'action_type.cpp',
                         'authorization_manager.cpp',
                         'authorization_session.cpp',
                         'auth_decorations.cpp',
                         'authz_manager_external_state.cpp',
                         'authz_manager_external_state_local.cpp',
                         'authz_session_external_state.cpp',
                         'privilege.cpp',
                         'privilege_parser.cpp',
                         'resource_pattern.cpp',
                         'role_graph.cpp',
                         'role_graph_update.cpp',
                         'role_name.cpp',
                         'role_graph_builtin_roles.cpp',
                         'user.cpp',
                         'user_document_parser.cpp',
                         'user_management_commands_parser.cpp',
                         'user_name.cpp',
                         'user_set.cpp'],
            LIBDEPS=['sasl_options',
                     '$BUILD_DIR/mongo/base',
                     '$BUILD_DIR/mongo/bson/mutable/mutable_bson',
                     '$BUILD_DIR/mongo/bson/util/bson_extract',
                     '$BUILD_DIR/mongo/crypto/scramauth',
                     '$BUILD_DIR/mongo/db/common',
                     '$BUILD_DIR/mongo/db/ops/update_driver',
                     '$BUILD_DIR/mongo/db/namespace_string',
                     '$BUILD_DIR/mongo/db/service_context',
                     '$BUILD_DIR/mongo/util/md5'])

env.Library('authcommon',
            ['internal_user_auth.cpp'],
            LIBDEPS=[
                '$BUILD_DIR/mongo/base',
                '$BUILD_DIR/mongo/bson/mutable/mutable_bson',
                '$BUILD_DIR/mongo/bson/util/bson_extract',
            ])

env.Library('authorization_manager_global',
            [
                'authorization_manager_global.cpp',
            ],
            LIBDEPS=[
                'authcore',
                '$BUILD_DIR/mongo/db/server_options_core',
                '$BUILD_DIR/mongo/db/service_context',
            ])

env.Library('authorization_manager_mock_init',
            [
                'authorization_manager_mock_init.cpp'
            ],
            LIBDEPS=[
                'authcore',
                'authmocks',
                '$BUILD_DIR/mongo/db/service_context',
            ])

env.Library('authservercommon',
            [
                'authz_session_external_state_server_common.cpp',
                'sasl_commands.cpp',
                'security_key.cpp',
            ],
            LIBDEPS=[
                '$BUILD_DIR/mongo/db/commands/core',
                'authcommon',
                'authcore',
                'authmocks',
                'authorization_manager_global',
                'saslauth',
                'security_file',
            ])

env.Library('security_file',
            ['security_file.cpp'],
            LIBDEPS=[
                '$BUILD_DIR/mongo/base',
            ],
)

env.Library('sasl_options',
            ['sasl_options.cpp'],
            LIBDEPS=[
                '$BUILD_DIR/mongo/base',
                '$BUILD_DIR/mongo/db/server_parameters',
                '$BUILD_DIR/mongo/util/options_parser/options_parser',
            ],
)

env.Library('saslauth',
             ['native_sasl_authentication_session.cpp',
             'sasl_authentication_session.cpp',
             'sasl_plain_server_conversation.cpp',
             'sasl_scramsha1_server_conversation.cpp',
             'sasl_server_conversation.cpp'],
             LIBDEPS=[
                'authcore',
                'authmocks', # Wat?
                'sasl_options',
                '$BUILD_DIR/mongo/crypto/scramauth',
                '$BUILD_DIR/mongo/db/commands/test_commands_enabled',
                '$BUILD_DIR/mongo/util/net/network',
             ],
)

env.Library('authmongod',
            ['authz_manager_external_state_d.cpp',
             'authz_session_external_state_d.cpp',
             'auth_index_d.cpp',
             'impersonation_session.cpp'
            ],
            LIBDEPS=[
                'authservercommon',
                '$BUILD_DIR/mongo/db/repl/repl_coordinator_global',
                '$BUILD_DIR/mongo/db/server_parameters',
            ],
            LIBDEPS_TAGS=[
                # Depends on files db_raii.cpp and catalog support files from serverOnlyFiles
                'incomplete',
            ],
)

env.Library('authmongos',
            ['authz_manager_external_state_s.cpp',
             'authz_session_external_state_s.cpp',
             'user_cache_invalidator_job.cpp'],
            LIBDEPS=[
                'authservercommon',
                '$BUILD_DIR/mongo/s/catalog/dist_lock_manager',
                '$BUILD_DIR/mongo/s/coreshard',
            ],
            LIBDEPS_TAGS=[
                # Depends on inShutdown
                'incomplete',
            ],
)

env.Library(
    target='authmocks',
    source=[
        'authz_manager_external_state_mock.cpp'
    ],
    LIBDEPS=[
        '$BUILD_DIR/mongo/db/matcher/expressions',
        '$BUILD_DIR/mongo/db/ops/update_driver',
        '$BUILD_DIR/mongo/db/service_context',
        'authcore'
    ]
)

env.CppUnitTest('action_set_test', 'action_set_test.cpp',
                LIBDEPS=['authcore', 'authmocks', 'saslauth'])
env.CppUnitTest('privilege_parser_test', 'privilege_parser_test.cpp',
                LIBDEPS=['authcore', 'authmocks', 'saslauth'])
env.CppUnitTest('role_graph_test', 'role_graph_test.cpp',
                LIBDEPS=['authcore', 'authmocks', 'saslauth'])
env.CppUnitTest('user_document_parser_test', 'user_document_parser_test.cpp',
                LIBDEPS=['authcore', 'authmocks', 'saslauth'])
env.CppUnitTest('user_set_test', 'user_set_test.cpp',
                LIBDEPS=['authcore', 'authmocks', 'saslauth'])
env.CppUnitTest('authorization_manager_test', 'authorization_manager_test.cpp',
                LIBDEPS=['authcore', 'authmocks', 'saslauth'])
env.CppUnitTest('authorization_session_test', 'authorization_session_test.cpp',
                LIBDEPS=['authcore', 'authmocks', 'saslauth'])
